const useLocalStorage = true;
export const LANG_CHANGE_EVENT = Symbol('LANG_CHANGE');
export const localeInfo: { [key: string]: any } = {
  'en-US': {
    messages: {},
    locale: 'en-US',
  },
  'zh-CN': {
    messages: {},
    locale: 'zh-CN',
  },
};

/**
 * 获取当前选择的语言
 * @returns string
 */
export const getLocale = () => {
  // runtime getLocale for user define
  //   const runtimeLocale = applyRuntimeLocalePlugin({});
  //   if (typeof runtimeLocale?.getLocale === 'function') {
  //     return runtimeLocale.getLocale();
  //   }
  // please clear localStorage if you change the baseSeparator config
  // because changing will break the app
  const lang =
    navigator.cookieEnabled &&
    typeof localStorage !== 'undefined' &&
    useLocalStorage
      ? window.localStorage.getItem('umi_locale')
      : '';
  // support baseNavigator, default true
  let browserLang;
  const isNavigatorLanguageValid =
    typeof navigator !== 'undefined' && typeof navigator.language === 'string';
  browserLang = isNavigatorLanguageValid
    ? navigator.language.split('-').join('-')
    : '';
  return lang || browserLang || 'zh-CN';
};
